import os
from typing import List

from langchain.output_parsers import PydanticOutputParser, OutputFixingParser
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_openai import ChatOpenAI

class Actor(BaseModel):
    name: str = Field(description="name of an actor")
    film_names: List[str] = Field(description="list of names of films they starred in")

llm = ChatOpenAI(model="gpt-3.5-turbo", api_key=os.environ["OPENAI_API_KEY_ZHIHU"],base_url=os.environ["OPENAI_API_BASE_ZHIHU"])

parser = PydanticOutputParser(pydantic_object=Actor)
parser2 = OutputFixingParser.from_llm(parser=parser, llm=llm)
misformatted = "{'name': 'Tom Hanks', 'film_names': ['Forrest Gump']}"

print(parser2.parse(misformatted))